package ba02;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.File;

/**
 * @author 飞哥
 * @version V1.0
 * @package ba02
 * @date 2021/7/25 16:46
 */
public class SpringTest02 {
    @Test
    /**
     * 测试set注入传入引用数据类型
     */
    public void test01() {
        ApplicationContext ac = new ClassPathXmlApplicationContext("ba02/applicationContext.xml");
        Student student = (Student) ac.getBean("myStudent");
        System.out.println("学生信息：" + student);
    }

    @Test
    /**
     * 测试使用name属性实现构造注入
     */
    public void test02() {
        ApplicationContext ac = new ClassPathXmlApplicationContext("ba02/applicationContext.xml");
        Student student = (Student) ac.getBean("myStudent02");
        System.out.println("学生信息1：" + student);
        Student student1 = (Student) ac.getBean("myStudent04");
        System.out.println("学生信息2：" + student1);
    }

    @Test
    /**
     * 测试使用index属性实现构造注入
     */
    public void test03() {
        ApplicationContext ac = new ClassPathXmlApplicationContext("ba02/applicationContext.xml");
        Student student = (Student) ac.getBean("myStudent03");
        System.out.println("学生信息：" + student);
    }

    @Test
    /**
     * 测试使用File类的构造方法
     * public File(String parent, String child)
     */
    public void test04() {
        ApplicationContext ac = new ClassPathXmlApplicationContext("ba02/applicationContext.xml");
        File myFile = (File) ac.getBean("myFile");
        System.out.println("文件的名字是：" + myFile.getName());
    }
}
